#ifndef _Water_H__
#define _Water_H__

#include "d3dheaders.h"
#include "video/ShaderWater.h"
#include "video/Camera.h"
#include "video/Texture.h"
#include "video/Renderable.h"

namespace KEngine
{

class ShaderWater;
class SceneManager;
class Water : public Renderable
{
	friend class ShaderWater;

public:
	struct VERTEX
	{
		D3DXVECTOR3 pos;
		float u, v;
		static const DWORD FVF = D3DFVF_XYZ | D3DFVF_TEX1;
	};

public:
	Water();
	virtual ~Water();

	bool create(const D3DXVECTOR3& pos, float width, float length);
	bool beginScene(Camera* camera);
	void endScene(Camera* camera);
	
	virtual void render(Camera* camera, TimeValue t);
	void drawPrimitive();

protected:
	bool createShader();

protected:
	ShaderWater*		mShader;

	Texture*			mWaveTex;
	
	ID3DTexture*	mEnvTex;
	ID3DSurface*	mEnvSurface;
	ID3DSurface*	mOldSurface;

	D3DXPLANE			mPlane;
	D3DXVECTOR3			mPos;
	float				mWidth;
	float				mLength;

	VERTEX				mVertices[4];
	
	friend class SceneManager;
	SceneManager*		_sceneMgr;
};

}

#endif //